package com.sari.common.utils;

import com.alibaba.fastjson.JSONObject;
//import org.apache.commons.httpclient.Header;
//import org.apache.commons.httpclient.HttpClient;
//import org.apache.commons.httpclient.NameValuePair;
//import org.apache.commons.httpclient.methods.PostMethod;


public class SMSMsg {

//    public static int sendMsg(String phoneNumber,String text)throws Exception{
//        HttpClient client = new HttpClient();
//        PostMethod post = new PostMethod("http://utf8.api.smschinese.cn/");
//        post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");//在头文件中设置转码
//        NameValuePair[] data ={ new NameValuePair("Uid", "kongwj"),
//                new NameValuePair("Key", "b7f43b9d823ba53f993a"),
//                new NameValuePair("smsMob",phoneNumber),
//                new NameValuePair("smsText",text)};
//        post.setRequestBody(data);
//
//        client.executeMethod(post);
//        Header[] headers = post.getResponseHeaders();
//        int statusCode = post.getStatusCode();
//        System.out.println("statusCode:"+statusCode);
//        post.releaseConnection();
//        return statusCode;
//    }

    public static int sendMsg(String phoneNumber,String text)throws Exception{

        String url = "http://utf8.api.smschinese.cn/";
        JSONObject param = new JSONObject();
        param.put("Uid","kongwj");
        param.put("Key","b7f43b9d823ba53f993a");
        param.put("smsMob",phoneNumber);
        param.put("smsText",text);
        param.put("Uid","kongwj");
        HttpClient.post(url,param);
        return 200;
    }

    public static void main(String[] args){
        try {
            SMSMsg.sendMsg("15221350266", "你好！短信测试。");
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
